import { get, post, put, del } from "@/request";

// 排班记录接口
export interface ISchedule {
  scheduleId?: number | string | null;
  staffId: number | string;
  staffName: string;
  dutyDay: string; // 格式："yyyy-MM-dd"
  scheShift: {
    shiftId: number | string;
    shiftName: string;
    startTime: string; // 格式："HH:mm:ss"
    endTime: string; // 格式："HH:mm:ss"
    workingHours: number | null;
    status: number;
    deptId: number | string;
    createTime?: string;
    updateTime?: string;
  };
  shiftId: number | string;
  deptId: number | string;
  status: number; // 0-特殊情况未正常执行,1-正常执行
  managerName: string;
  createTime?: string;
  updateTime?: string;
}

// 排班查询条件接口
export interface IScheduleCondition {
  scheduleId?: number | string;
  staffId?: number | string;
  staffName?: string;
  dutyDay?: string;
  shiftId?: number | string;
  deptId?: number | string;
  status?: number;
  managerName?: string;
  year?: number;
  month?: number;
}

// 批量操作请求接口
interface IBatchScheduleRequest {
  schedules: ISchedule[];
}

/**
 * 批量新增排班
 * @param data 排班数据列表
 */
export const batchAddSchedule = (data: IBatchScheduleRequest) => {
  return post("/schedule/schedule", data);
};

/**
 * 批量新增或更新排班
 * @param data 排班数据列表
 */
export const batchSaveOrUpdateSchedules = (data: IBatchScheduleRequest) => {
  return post("/schedule/schedule/batch-save-or-update", data);
};

/**
 * 根据条件查询排班
 * @param condition 查询条件
 */
export const searchSchedules = (condition: IScheduleCondition) => {
  return post<{ data: ISchedule[] }>("/schedule/schedule/search", condition);
};

/**
 * 删除排班
 * @param scheduleId 排班ID
 */
export const deleteSchedule = (scheduleId: number | string) => {
  return del(`/schedule/schedule/${scheduleId}`);
};